﻿using UnityEngine;
using System.Collections;

public class FollowPlayer : MonoBehaviour {

	Transform player;
	public Vector3 cameraOffset = new Vector3(10.0f, 10.0f, 0);
	public float screenWidthMoveable = 10.0f;
	public float screenHeightMovable = 10.0f;

	// Use this for initialization
	void Start ()
	{
		player = GameObject.FindGameObjectWithTag ("Player").transform;
	}
	
	// Update is called once per frame
	void Update () 
	{
		if(Mathf.Abs (player.position.x) < screenWidthMoveable)
		{
			float horizontalDistToPlayer = player.transform.position.x - transform.position.x;
			transform.position = Vector3.Lerp(transform.position, transform.position + Vector3.right * horizontalDistToPlayer + Vector3.up* cameraOffset.y, 0.3f);
		}

		if(Mathf.Abs (player.position.z) < screenHeightMovable)
		{
			float verticalDistToPlayer = player.transform.position.z - transform.position.z - cameraOffset.z;
			transform.position = Vector3.Lerp(transform.position, transform.position + Vector3.forward * verticalDistToPlayer + Vector3.up* cameraOffset.y, 0.3f);
		}

		//transform.position = Vector3.Lerp (transform.position, player.position + Vector3.up * distFromPlayerUp -( Vector3.forward * distFromPlayerBack), 0.3f);
	}
}
